<template>
	<view>
		<block v-if="list.length>0">
			<scroll-view scroll-y="true" :style="'height:' + height + 'px;'" style="height: 100%;width: 100%;"
				class="column" :refresher-triggered="refresherTriggered" :refresher-enabled="true"
				@refresherrefresh="refresherrefresh" @scrolltolower="scrolltolower">
				<view v-for="(item,index) in list" :key="index">
					<view class="content" @click="gotoChat(item)">
						<image v-if="item.user.avatar" :src='item.user.avatar' mode="aspectFit" class="avatar"></image>
						<image v-else src='@/static/images/f.png' mode="aspectFit" class="avatar"></image>
						<view class="nametxt">{{item.user.nickname}}</view>
						<view class="timetxt">{{item.creat_time}}</view>
						<text class="iconfont icon-xiangyou"></text>
					</view>
				</view>
			</scroll-view>
		</block>
		<block v-else>
			<emptyPage title="暂无数据~"></emptyPage>
		</block>
	</view>
</template>

<script>
	import emptyPage from '@/components/emptyPage.vue'
	import {
		rpUserlist
	} from '@/api/doc_appointment.js';
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				doctor_id: 0,
				limit: 20,
				page: 1,
				list: [],
				height:0,
				refresherTriggered:false
			}
		},
		onShow() {
			this.getList()
		},
		onLoad(options) {
			this.doctor_id = options.doctor_id
			this.height = uni.getSystemInfoSync().windowHeight
			
		},
		methods: {
			getList() {
				let that = this
				let param = {
					'page': this.page,
					'limit': this.limit
				}
				rpUserlist(param).then(res => {
					if (that.page == 1) {
						that.list = res.data.list
					} else {
						that.list = that.list.concat(res.data.list)
					}
				})
			},
			scrolltolower() {
				this.page++
				this.getList()
			},

			refresherrefresh() {
				var that = this
				that.refresherTriggered = true;
				that.getList()
				console.log('自定义下拉刷新被触发');
				setTimeout(() => {
					that.refresherTriggered = false;
				}, 100);
			},
			gotoChat(item) {
				uni.navigateTo({
					url: '/pages/rp/rp_chat/rp_chat?isDoctor=1&order_id='+ item.order_id+ '&toUid='+item.uid
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	.timetxt {
		margin-right: 2px;
		font-size: 14px;
		color: #646464;
	}

	.nametxt {
		margin-left: 8px;
		display: flex;
		flex: 1;
		margin-right: 10px;
		font-size: 15px;
		color: #323232;
	}

	.avatar {
		width: 30px;
		height: 30px;
		border-radius: 15px;
	}

	.content {
		width: 100%;
		height: 50px;
		padding-left: 15px;
		padding-right: 15px;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-bottom: 1px solid #eaeaea;
	}
</style>